package ADBook.Advance;
import ADBook.Advance.info;

import java.util.HashMap;
import java.util.Map;
//to manage all the info

public class Manager {
	//count of the info
	private int count = 0;
	
	//store the info in an arraylist
	Map<String, info> manager = new HashMap<String, info>();
	//add 
	public void add(info info) {
		manager.put(info.get_name(),info);
		this.count++;
	}
	//delete 0 for false and 1 for true
	public boolean delete(String name) {
		if(!manager.containsKey(name)) {
			return false;
		} else {
			manager.remove(name);
			return true;
		}
	}
	//update the info,0 for update and 1 for add,by name
	public boolean update(info newinfo) {
		if(!manager.containsKey(newinfo.get_name())) {
			manager.put(newinfo.get_name(), newinfo);
			return false;
		} else {
			manager.replace(newinfo.get_name(), manager.get(newinfo.get_name()), newinfo);
			return true;
		}
	}
	//query
	public info query(String name) {
		if(!manager.containsKey(name)) {
			return null;
		} else {
			return manager.get(name);
		}
	}
}
